package com.baizhi.controller;


import com.baizhi.service.CmfzAdminService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengg
 * @since 2020-07-26
 */
@Controller
@RequestMapping("/admin")
public class CmfzAdminController {
    @Autowired
    private CmfzAdminService adminService;
    @RequestMapping("/login")
    public String login(String name,String pwd){
        boolean result=adminService.login(name,pwd);
        if(result){
            return "redirect:/success.jsp";
        }else{
            return "redirect:/error.jsp";
        }
    }

    @RequestMapping("/testHas")
    public String testHas(){
        adminService.testHas();
        return "redirect:/success.jsp";
    }
    @RequestMapping("/testNo")
    @RequiresRoles("test")
    public String testNo(){
        adminService.testNo();
        return "redirect:/success.jsp";
    }

    @RequestMapping("/testDate")
    @ResponseBody
    public String testDate(@RequestParam("date")@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate date){
        System.out.println(date+"===============");
        return "hello"+date;
    }
}
